package com.edz.from0507to0513apk.Accountsave.frag;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.edz.from0507to0513apk.R;
import com.edz.from0507to0513apk.Util.SpUtils;
import com.zhy.adapter.recyclerview.CommonAdapter;
import com.zhy.adapter.recyclerview.base.ViewHolder;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class SettingFrag extends Fragment {

    private View view_setting;
    @BindView(R.id.toolbar_setting)
    Toolbar toolbar_setting;
    @BindView(R.id.rv_setting_list)
    RecyclerView rv_setting_list;

    public SettingFrag() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view_setting = inflater.inflate(R.layout.fragment_setting, container, false);
        ButterKnife.bind(this,view_setting);
        initData();
        initView();
        return view_setting;
    }

    private void initData() {
        final boolean isLogin = (boolean) SpUtils.get(getActivity(),"isLogin",false);

        final List<String> list = new ArrayList<>();

        list.add("修改密码");
        list.add("关于我们");
        list.add("退出登录");

        rv_setting_list.setLayoutManager(new LinearLayoutManager(getActivity()));
        rv_setting_list.setAdapter(new CommonAdapter<String>(getActivity(),R.layout.item_setting,list) {
            @Override
            protected void convert(ViewHolder holder, String string, final int position) {
//                if(isLogin){
//                    switch (position){
//                        case 0:
//                        case 1:
//                        case 2:
//                    }
//                }
                holder.setText(R.id.tv_preview,list.get(position));
                holder.setOnClickListener(R.id.tv_preview, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        switch (position){
                            case 0:
                                Toast.makeText(getActivity(),"0",Toast.LENGTH_SHORT).show();
                                break;
                            case 1:
                                Toast.makeText(getActivity(),"1",Toast.LENGTH_SHORT).show();
                                break;
                            case 2:
                                Toast.makeText(getActivity(),"2",Toast.LENGTH_SHORT).show();
                                break;
                                default:break;
                        }
                    }
                });
            }
        });
    }

    private void initView() {
        toolbar_setting.setTitle("设置");
    }
}
